<template>
    <el-row :gutter="10">
        <el-col :span="12"><el-form-item label="订单号"><span>{{ form.number }}</span></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="客户名称"><span>{{ form.custName }}</span></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="订单日期"><span>{{ form.orderDate }}</span></el-form-item></el-col>
        <el-col :span="12"><el-form-item label="销售公司"><span>{{ form.sellerName }}</span></el-form-item></el-col>
    </el-row>
    <ts-card >
    <template #header>
        <div style="display: flex;justify-content: space-between;">
            <span>附件列表</span>
        <el-button type="primary" icon="ts-icon-file-excel" @click="exportExcels">导出</el-button>
    </div>
    </template>
    <el-table :data="dataList" @selection-change="rowChange">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="title" label="模板标题" />
        <el-table-column prop="fileName" label="文件名" />
        <el-table-column fixed="right" label="操作">
            <template #default="scope">
                <el-button size="small" icon="ts-icon-file-excel" @click="exportExcel(scope.row)">导出</el-button>
                <el-button size="small" :icon="Reading" @click="detailExcel(scope.row)"> 预览</el-button>
            </template>
        </el-table-column>
    </el-table>
</ts-card>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from "vue-router";
import API from '@/api/model/om'
import reportAPI from "@/api/model/report";
import { deepClone } from '@/utils/arr';
import { Upload, Reading } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
const router = useRouter()
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {},
    },
});
const form = ref({})
const dataList = ref([])
const files = ref([])
onMounted(() => {
    getInit()
})
const getInit = async () => {
    let res = await API.order.exportExcelTemplateList.post(props.paramsData)
    if (res.code == '200') {
        console.log(res)
        form.value = res.data
        dataList.value = res.dataList
    }
}
const exportExcel = async (row) => {
    let res = await reportAPI.exportToExcel.post({
        fileName: row.fileName,
        fieldMap: row,
    });
    if (res.code == '200') {
        window.open(res.fileName)
    }
}
const detailExcel = async (row) => {
    router.push({
        path: '/reportView',
        query: row
    })
}
const rowChange = async (rows) => {

        files.value = rows

}
const exportExcels = async (row) => {
    if (files.value.length < 2) {
        ElMessage.warning({ message: '至少选择两条记录' })
    }
    else{
        let res = await reportAPI.zipFile.post({
        dataList:files.value
    });
    if (res.code == '200') {
        window.open(res.fileName)
    }
    }

}
</script>